package com.dyz.leetcode._02_string;

public class _38_countAndSay {
    public String countAndSay(int n) {
        StringBuilder curr = new StringBuilder("1");
        StringBuilder prev;
        for(int i=1; i<n; i++){
            prev = curr;
            curr=new StringBuilder();

            char say = prev.charAt(0);
            int count = 1;
            for(int j=1; j<prev.length(); j++){
                if(prev.charAt(j)==say){
                    count++;
                }else{
                    curr.append(count).append(say);
                    say = prev.charAt(j);
                    count=1;
                }
            }
            //不要漏掉最后一次
            curr.append(count).append(say);
        }
        return curr.toString();
    }
}
